/**
*
* Copyright (c) 2011 galaxy engine team.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
*  Abstract:
*    
*
*  Author:
*    freecnjet (freecnjet@gmail.com)
*
*  Revision History:
*    Created on: 2011-02-23
*
*/

#ifndef _TYPE_H_
#define _TYPE_H_


__BEGIN_NAMESPACE

/*****************************************************************************************
* Define platform independent variable types
*****************************************************************************************/
#undef boolean
typedef unsigned char       boolean;

#undef byte
typedef unsigned char       byte;

#undef wchar
typedef wchar_t             wchar;

#undef word
typedef unsigned short      word;

#undef dword
typedef unsigned long       dword;

#undef hyper
typedef long long           hyper;

#undef qword
typedef unsigned long long  qword;

/**
* warning: only use follow type instead of std c/c++ types.
*    void,
*    boolean,
*    char,
*    wchar,
*    byte,
*    short,
*    word,
*    long,
*    dword,
*    hyper,
*    qword,
*    float,
*    double
*/


/*****************************************************************************************
* Define common const values
*****************************************************************************************/
#ifndef NULL
#define NULL
#endif

#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TEXT
#if defined(UNICODE) || defined(_UNICODE)
#   define TEXT(x) L##x
#else
#   define TEXT(x) x
#endif
#endif


/*****************************************************************************************
* ctype.h
*****************************************************************************************/
FORCEINLINE int Isalnum ( int c ) {
	return ('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9') ? 1 : 0;
}

FORCEINLINE int Isalpha ( int c ) {
	return ('a'<=c&&c<='z' || 'A'<=c&&c<='Z') ? 1 : 0;
}

FORCEINLINE int Iscntrl( int c ) {
	return iscntrl(c);
}

FORCEINLINE int Isdigit( int c ) {
	return ('0'<=c&&c<='9') ? 1 : 0;
}

//isgraph

FORCEINLINE int Islower( int c ) {
	return ('a'<=c&&c<='z') ? 1 : 0;
}

//int isprint ( int c );
//int ispunct ( int c );

FORCEINLINE int Isspace ( int c ) {
	return (' '==c || '\t'==c || '\n'==c || '\v'==c || '\f'==c || '\r'==c) ? 1 : 0;
}

FORCEINLINE int Isupper ( int c ) {
	return ('A'<=c&&c<='Z') ? 1 : 0;
}

FORCEINLINE int Isxdigit ( int c ) {
	return (('0'<=c&&c<='9') || ('A'<=c&&c<='F')|| ('a'<=c&&c<='f')) ? 1 : 0;
}

FORCEINLINE int Tolower ( int c ) {
	return ('A'<=c&&c<='Z') ? (c+'a'-'A') : c;
}

FORCEINLINE int Toupper ( int c ) {
	return ('a'<=c&&c<='z') ? (c-'a'+'A') : c;
}


/**
* UUID
*/
class CORE_API UUID {
public:
	union {
		struct {
			byte mBytes[16];
		};
		struct {
			dword mData1;
			word  mData2;
			word  mData3;
			byte  mData4[8];
		};
	};

	UUID();
	UUID( const char* name );
	UUID( const UUID& other );

	bool operator == (const UUID& other) const;
	bool operator != (const UUID& other) const {
		return !operator==(other);
	}
};


/**
* endian
*/
template< typename _T> 
inline void SwapEndian( _T& org ) {
	const int count = sizeof(T)/2;
    const byte* bytes = &org;
	for( int i=0; i<count; ++i ) {
		byte t = bytes[i];
        bytes[i] = bytes[sizeof(T)-1-i];
	}
}	

template< typename _T> 
inline void ToBigEndian( _T& org ) {
#if( ENDIAN==ENDIAN_LITTLE )
	return SwapEndian<_T>(org);
#endif
}

template< typename _T> 
inline void ToLittleEndian( _T& org ) {
#if( ENDIAN==ENDIAN_BIG )
	return SwapEndian<_T>(org);
#endif	
}


__END_NAMESPACE


#endif // _TYPE_H_